package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.ApartmentInfoService;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    private LabelInfoMapper labelInfoMapper;

    //根据条件分页查询租约列表
    @Override
    public Page<AgreementVo> pageAgreementByQuery(Page<AgreementVo> agreementVoPage, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.pageAgreementByQuery(agreementVoPage,queryVo);
    }

    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;
    @Autowired
    private RoomInfoMapper roomInfoMapper;
    @Autowired
    private PaymentTypeMapper paymentTypeMapper;
    @Autowired
    private LeaseTermMapper leaseTermMapper;
    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;




    //根据id查询租约信息
    @Override
    public AgreementVo getAgreementById(Long id) {
        //根据id先查到租约信息
        //再根据租约信息里的数据去分别查找其他的详情信息
        LeaseAgreement leaseAgreement = leaseAgreementMapper.selectById(id);
        AgreementVo agreementVo = new AgreementVo();
        BeanUtils.copyProperties(leaseAgreement, agreementVo);
        //        left join apartment_info ai
        //        left join room_info ri
        //        left join payment_type pt
        //        left join lease_term lt
        agreementVo.setApartmentInfo(apartmentInfoMapper.selectById(leaseAgreement.getApartmentId()));
        agreementVo.setRoomInfo(roomInfoMapper.selectById(leaseAgreement.getRoomId()));
        agreementVo.setPaymentType(paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId()));
        agreementVo.setLeaseTerm(leaseTermMapper.selectById(leaseAgreement.getLeaseTermId()));
        return agreementVo;
    }
}




